var app = getApp();
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: !0,
    zx_id: 0,
    currentTab: 0,
    bigMask: false,
    zixun: [{},{},{}],
    page: 0,
    pagesize: 10,
    reward: [1, 2, 3, 4, 5, 6, 7],
    consulList: [{
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
    ],
    footer: {
      footerTab: 1,
      footerlist: [{
        text: "首页",
        img: "/hyb_yl/images/tab01.png",
        selimg: "/hyb_yl/images/tab1.png",
        url: "/hyb_yl/tabBar/index/index"
      }, {
        text: "资讯",
        img: "/hyb_yl/images/tab02.png",
        selimg: "/hyb_yl/images/tab2.png",
        url: "/hyb_yl/tabBar/jibingyufang/jibingyufang"
      }, {
        text: "分享",
        img: "/hyb_yl/images/tab03.png",
        selimg: "/hyb_yl/images/tab3.png",
        url: "/hyb_yl/tabBar/community/community"
      }, {
        text: "药房",
        img: "/hyb_yl/images/tab04.png",
        selimg: "/hyb_yl/images/tab4.png",
        url: "/hyb_yl/tabBar/shop/shop"
      }, {
        text: "问诊",
        img: "/hyb_yl/images/tab04.png",
        selimg: "/hyb_yl/images/tab4.png",
        url: "/hyb_yl/tabBar/fastnavigate/fastnavigate"
      }, {
        text: "我的",
        img: "/hyb_yl/images/tab05.png",
        selimg: "/hyb_yl/images/tab5.png",
        url: "/hyb_yl/tabBar/my/my"
      }]
    },
    tabindex: 0,
    deparshow: false,
  },
  // 关闭遮罩
  close_zhe:function(){
    this.setData({
      deparshow:false
    })
  },
  tabChose: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      tabchoseStyle: index,
      tabcid: e.currentTarget.dataset.tabcid
    })
  },
  departab: function (e) {
    var that = this;
    const tabindex = e.currentTarget.dataset.dex;
    console.log(tabindex);

    if (tabindex == 0) {
      var tabpid = 0;
    } else {
      var tabpid = e.currentTarget.dataset.zx_id;
    }
    console.log(tabpid)

    that.setData({
      tabindex: tabindex,
      tabpid: tabpid,
      zixun: [],
      page: 0
    })
    this.getzixunlist(tabpid)
  },
  deparlist: function () {
    if (this.data.deparshow) {
      this.setData({
        deparshow: false
      })
    } else {
      this.setData({
        deparshow: true
      })
    }
  },
  departabs: function (e) {
    console.log(e);
    var that = this;
    const index = e.currentTarget.dataset.dex;
    if (index == 0) {
      var tabpid = 0;
    } else {
      var tabpid = e.currentTarget.dataset.zx_id;
    }
    that.setData({
      tabindex: index,
      deparshow: false,
      tabpid: tabpid,
      zixun: [],
      page: 0
    })
    this.getzixunlist(tabpid)
  },
  tiaozhuan: function (e) {
    console.log(e.currentTarget.dataset.zx_id)
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zixunList/zixunList?zx_id=' + e.currentTarget.dataset.zx_id,
    })
  },
  goBack: function () {
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zixunList/zixunList',
    })
  },
  // 点击切换套餐选项卡
  // taocan: function (e) {
  //   // console.log(e);
  //   var that = this;
  //   var zx_id = e.currentTarget.dataset.id
  //   app.util.request({
  //     'url': 'entry/wxapp/zixun.zixunyi',
  //     data: {
  //       zx_id: zx_id
  //     },
  //     success: function (res) {
  //       console.log(res)
  //       that.setData({
  //         zixun: res.data,
  //         zx_id: zx_id
  //       })
  //     },
  //     fail: function (err) {
  //       console.log(err)
  //     },
  //   })
  //   that.setData({
  //     currentTab: e.currentTarget.dataset.index
  //   })

  // },
  btdetail(e) {
    var id = e.currentTarget.dataset.id
    var p_id = e.currentTarget.dataset.p_id
    var zid = e.currentTarget.dataset.zid
    //增加阅读数
    app.util.request({
      'url': 'entry/wxapp/zixun.addyuedu',
      data: {
        id: id,
      },
      success: function (res) {
        console.log(res)
      },
      fail: function (err) {
        console.log(err)
      },
    })
    app.util.request({
      'url': 'entry/wxapp/zixun.erweima',
      data: {
        id: id,
        p_id: p_id
      },
      success: function (res) {
        console.log(res)
      },
      fail: function (err) {
        console.log(err)
      },
    })
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zixunanlixq/zixunanlixq?id=' + id + '&p_id=' + p_id + '&zid=' + zid,
    })
  },
  // taocan1: function (e) {
  //   console.log(e);
  //   var that = this;
  //   var zx_id = e.currentTarget.dataset.id
  //   var index = e.currentTarget.dataset.index
  //   console.log(index)
  //   app.util.request({
  //     'url': 'entry/wxapp/zixun.zixunyi',
  //     data: {
  //       zx_id: zx_id
  //     },
  //     success: function (res) {
  //       console.log(res)
  //       that.setData({
  //         zixun: res.data,
  //         currentTab: index
  //       })
  //     },
  //     fail: function (err) {
  //       console.log(err)
  //     },
  //   })
  // },
  searchbtn() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/search/search',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getfooter()
    var zx_id = options.zx_id
    var index = options.index
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getBase();
    var that = this;
    console.log(page)
    // app.util.request({
    //   'url': "entry/wxapp/Index.zixunfenlei",
    //   success: function (res) {
    //     console.log(res)
    //     var zx_id = res.data[0].zx_id
    //     app.util.request({
    //       'url': 'entry/wxapp/zixun.zixunyi',
    //       data: {
    //         zx_id: zx_id,
    //         page: page
    //       },
    //       success: function (res) {
    //         console.log(res, "====================")
    //         that.setData({
    //           zixun: res.data,
    //         })
    //       },
    //       fail: function (err) {
    //         console.log(err)
    //       },
    //     })
    //     that.setData({
    //       taocan: res.data,
    //       zx_id: zx_id
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },
    // })
    that.setData({
      currentTab: index,
      bgc: bgc,
      zx_id: zx_id
    })
  },
  getBase: function () {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/index.base',
      success: function (res) {
        console.log(res);
        that.setData({
          baseinfo: res.data,
        })
        
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  toast: function () {
    wx.redirectTo({
      url: '/hyb_yl/tabBar/index/index'
    })
  },
  toast1: function (e) {
    //console.log(e)
    wx.redirectTo({
      url: '/hyb_yl/tabBar/community/community'
    })
  },
  toast2: function () {
    wx.redirectTo({
      url: '/hyb_yl/mysubpages/pages/shop/shop'
    })
  },
  toast3: function () {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function (res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function (err) {
        console.log(err)
      },

    })
    setTimeout(function () {
      wx.redirectTo({
        url: '/hyb_yl/tabBar/my/my'
      })
    }, 350)
  },
  toast4() {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function (res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function (err) {
        console.log(err)
      },

    })
    wx.redirectTo({
      url: '/hyb_yl/userLife/pages/jibingyufang/jibingyufang'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getShowzixunfenlei()
    this.getzixunlist(0)
    this.getalluser()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideNavigationBarLoading()
    var that = this
    var zx_id = that.data.zx_id
    var openid = wx.getStorageSync('openid')
    console.log(openid)
    if (openid) {
      that.setData({
        bigMask: true
      })
    } else {
      that.setData({
        bigMask: false
      })
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getzixunlist();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //咨询
  getfooter() {
    var that = this
    app.util.request({
      url: "entry/wxapp/index.footerlist",
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (resing) {
        let footers = {
          footerTab: 1,
          footerlist: resing.data
        };
        that.setData({
          footer: footers
        })
      }
    })
  },
  getzixunlist: function (tabpid) {
    var that = this;
    that.data.zx_id = tabpid
    if(that.data.page == 0)
    {
      that.setData({
        isLoading: !0,
      })
    }
    
    app.util.request({
      'url': 'entry/wxapp/zixun.zixunlists',
      data: {
        tabIndex: 0,
        page: that.data.page,
        pagesize: that.data.pagesize,
        zx_id: that.data.zx_id
      },
      success: function (res) {
        console.log("z资讯",res)
        var page = that.data.page + 1;
        that.setData({
          page: page,
          zixun: that.data.zixun.concat(res.data),
          
        })
        if(that.data.page == 1)
        {
          that.setData({
            isLoading: !1
          })
        }
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  getalluser() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zixun.getalluser',
      success: function (res) {
        console.log(res, "====================")
        that.setData({
          rew: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  getShowzixunfenlei: function () {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zixun.showzixunfenlei',
      success: function (res) {
        console.log(res, "====================")
        that.setData({
          taocan: res.data,
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },

})